﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;


namespace Migraine.BLL
{
    public class BenhNhanBUO : IBUO<tbl_BenhNhan>
    {
        BenhDataContext context = new BenhDataContext();
        public tbl_BenhNhan GetSingle(int id)
        {
            return context.tbl_BenhNhans.Where(n => n.idBenhNhan == id).ToList<tbl_BenhNhan>().FirstOrDefault();
        }
        public List<tbl_BenhNhan> GetAll()
        {
            return context.tbl_BenhNhans.OrderByDescending(n => n.idBenhNhan).ToList<tbl_BenhNhan>();
        }
        public bool Insert(tbl_BenhNhan obj)
        {
            try
            {
                context.tbl_BenhNhans.InsertOnSubmit(obj);
                context.SubmitChanges();
                return true;
            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool Update(int id, tbl_BenhNhan obj)
        {
            try
            {
                tbl_BenhNhan bn = context.tbl_BenhNhans.Where(n => n.idBenhNhan == id).ToList<tbl_BenhNhan>().FirstOrDefault();
                bn = obj;
                context.SubmitChanges();
                return true;

            }
            catch (Exception)
            {

                return false;
            }
        }
        public bool Delete(int id)
        {
            try
            {
                tbl_BenhNhan obj = context.tbl_BenhNhans.Where(n => n.idBenhNhan == id).First<tbl_BenhNhan>();
                if (obj != null)
                {
                    context.tbl_BenhNhans.DeleteOnSubmit(obj);
                    context.SubmitChanges();
                    return true;
                }
                else
                {
                    return false;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public bool Delete(tbl_BenhNhan obj)
        {
            throw new NotImplementedException();
        }
    }
}
